#include <iostream>

#include "srs_kernel_error.hpp"
#include "srs_kernel_log.hpp"
#include "srs_app_log.hpp"
#include "srs_service_log.hpp"
#include <srs_app_config.hpp>
#include <sstream>
#include <unistd.h>
using namespace std;

// @global log and context.
ISrsLog* _srs_log = new SrsFastLog();
ISrsThreadContext* _srs_context = new SrsThreadContext();
SrsConfig* _srs_config = new SrsConfig();

int main(int argc, char** argv) {
    std::cout << "Hello, World!" << std::endl;

    srs_error_t err = srs_success;

    // never use srs log(srs_trace, srs_error, etc) before config parse the option,
    // which will load the log config and apply it.
    if ((err = _srs_config->parse_options(argc, argv)) != srs_success) {
        srs_error_wrap(err, "config parse options");
    }
    // change the work dir and set cwd.
    int r0 = 0;
    string cwd = _srs_config->get_work_dir();
    if (!cwd.empty() && cwd != "./" && (r0 = chdir(cwd.c_str())) == -1) {
         srs_error_new(-1, "chdir to %s, r0=%d", cwd.c_str(), r0);
    }
    if ((err = _srs_config->initialize_cwd()) != srs_success) {
         srs_error_wrap(err, "config cwd");
    }

    // config parsed, initialize log.
    if ((err = _srs_log->initialize()) != srs_success) {
        srs_error_wrap(err, "log initialize");
    }

    srs_error_t tt =  srs_error_new(88, "send message");
    srs_trace("11111111111111111111");
    srs_info("333333");
    srs_error("666666");
    srs_error("Failed, %s",srs_error_desc(tt).c_str());

    getchar();
    return 0;
}